﻿using System;
using Core.Library;
using DataObject.Comment;

public partial class Controls_Comment_ListingByIdType : System.Web.UI.UserControl
{
    protected int Id;
    protected int TypeId;
    protected int PageIndex;
    protected int TotalRecords;
    protected string IsShowComment = "none";    

    protected void Page_Load(object sender, EventArgs e)
    {
        Id          = Utils.GetIdFromRequestString(Utils.Id, 0);
        TypeId      = Utils.GetIdFromRequestString(Utils.TypeId, 0);
        PageIndex   = Utils.GetIdFromRequestString(Utils.PageIndex, SettingValues.PageIndex);

        if (!IsPostBack)
            if (Id > 0 && TypeId > 0 && PageIndex > 0)
                ListCommentByIdTypeId();        
    }

    private void ListCommentByIdTypeId()
    {
        var totalRecords = 0;
        var lstComment = CommentController.PaginationComment(Id, TypeId, PageIndex, SettingValues.PageSize_5, ref totalRecords);

        if (lstComment != null && lstComment.Count > 0)
        {
            TotalRecords = totalRecords;

            rptComment.DataSource = lstComment;
            rptComment.DataBind();

            ltPager.Text = PagerUtility.PageLinks(PageIndex, SettingValues.PageSize_5, totalRecords,
                                                  SettingValues.PageStep,
                                                  UrlHelpers.ListPaginationByIdTypeId(Id, TypeId, "{0}"));
            IsShowComment = "block";
        }
    }
}